exports.sendManagerMessage = function(req, res) {

	var bodyParams = req.routeInfo.bodyParams;
	
	console.log('---22-22接收到的参数？？？222-2--')
	console.log(bodyParams)

	var openid = '';

	var nickname = '';

	var userInformation = 0;

	var fatherEnterprise = 0;

	function searchSaleInfo(cb) {

		R.SEND_HTTP(
			req,
			res, {
				url: CORE_APIConfig.coreAPI.userSearch.Request_Api_Url + "/u_id/" + bodyParams.u_id,
				method: 'POST',
				data: {
					fields: ['u_master_osid', 'u_is_manager', 'u_openid', 'u_nickname'].join(',')
				}
			},
			function(data) {

				if(data.result.data[0].u_is_manager == 1) {
					openid = data.result.data[0].u_openid;
					nickname = data.result.data[0].u_nickname;
				} else {
					userInformation = data.result.data
				}
				cb();

			}
		)
	}

	//查询销售根节点的父节点
	function searchSaleFatherEnterprise(cb) {

		if(userInformation == '0' || userInformation[0].u_is_manager == 1) {
			return cb()
		}
		R.SEND_HTTP(
			req,
			res, {
				url: CORE_APIConfig.coreAPI.organizationalStructureSearch.Request_Api_Url + "/os_id/" + userInformation[0].u_master_osid,
				method: 'POST',
				data: {
					fields: ['os_fid'].join(',')
				}
			},
			function(data) {

				fatherEnterprise = data.result.data;

				cb();

			}
		)
	}

	//查询销售根节点的父节点的用户openid
	function searchSaleFatherEnterpriseOpenid(cb) {

		if(userInformation == '0' || userInformation[0].u_is_manager == 1) {
			return cb()
		}
		R.SEND_HTTP(
			req,
			res, {
				url: CORE_APIConfig.coreAPI.userSearch.Request_Api_Url + "/u_master_osid/" + fatherEnterprise[0].os_fid,
				method: 'POST',
				data: {
					fields: ['u_openid'].join(',')
				}
			},
			function(data) {

				openid = data.result.data[0].u_openid;

				cb();

			}
		)
	}

	//发私信
	function sendPrivateMessage(cb) {
		
		console.log('------有没有openid??------')
		console.log(openid)

		if(openid == 0 || openid == '') {
			cb();
		} else {

			var params = {
				type: "xinDingDan",
				openid: openid,
				goUrls: "", //跳转
				name: nickname, //销售名
				productName: bodyParams.productName, //产品名
			}

			R.SEND_HTTP(
				req,
				res, {
					url: config.server.ip + ":" + config.server.port + CORE_APIConfig.coreAPI.templateMessagesSent.Request_Api_Name,
					method: 'POST',
					data: params
				},
				function(data) {

					cb();

				}
			)

		}
	}

	F.Serial([
		searchSaleInfo,
		searchSaleFatherEnterprise,
		searchSaleFatherEnterpriseOpenid,
		sendPrivateMessage
	], () => {
		RES.successResponse(res);
	})
}